package com.cn.kabalifemerchants.ui.page;

import com.cn.kabalifemerchants.api.Api;
import com.cn.kabalifemerchants.base.BasePresenter;
import com.cn.kabalifemerchants.callback.CacheCallBack;
import com.cn.kabalifemerchants.config.Constants;
import com.cn.kabalifemerchants.ui.page.bean.RecruitListBean;
import com.cn.kabalifemerchants.ui.page.bean.ShopInfoBean;
import com.cn.kabalifemerchants.utils.LoggerUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

/**
 * Created by 晓林 on 2020/10/14.
 * function:
 */
public class FragmentPagePresenter extends BasePresenter<FragmentPageView> {

    public void onShopInfoData(String token) {
        OkGo.<ShopInfoBean>get(Api.API_INDEX_SHOP_DETAILS)
                .headers("token", token)
//                .params("lon", lon)
//                .params("lat", lat)
//                .params("business_id", id)
                .execute(new CacheCallBack<ShopInfoBean>() {
                    @Override
                    public void onSuccess(Response<ShopInfoBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("商家详情：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onShopInfoSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }


    /**
     * 招聘列表
     *
     * @param token
     * @param page
     * @param limit
     * @param id
     */
    public void onRecruitListData(String token, int page, int limit, int id) {
        OkGo.<RecruitListBean>get(Api.API_RECRUIT_LIST)
                .headers("token", token)
                .params("type", 1)
                .params("page", page)
                .params("limit", limit)
                .params("business_id", id)
                .execute(new CacheCallBack<RecruitListBean>() {
                    @Override
                    public void onSuccess(Response<RecruitListBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("商家详情：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onRecruitListSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }
}
